Drag words with Ctrl-left/right
Select a block of chars with C-v , then press C-l or C-r to drag the selection around. These didn't work in vim80 (8/2017) - Line is completely messed up after a few C-r and C-l. :vmap xpgvlolo :vmap xhPgvhoho Comments Perhaps we need these mappings too: :vnoremap h :vnoremap l :vnoremap k :vnoremap j If you want to move the word currently under the cursor, the mappings above work just fine. Use bvw to highlight the current word first and you are good to move it around using Ctrl-Left and Ctrl-Right. ---- While we are being complete, you should add these to allow you to move the selected text up and down: vmap xjPgvjojo vmap xkPgvkoko Here is an alternate suggestion, with a number of enhancements. 1. Word selection. You can easily visually select a word before clicking by typing vaw, viw, vaW, or viW depending on your style of word. Or select multiple words like v2aw, or paragraphs, blocks, etc, see . If you want to click to select and move a word, just add your select code to a nmap, otherwise the same as the vmap above. See the example below. Note that this leaves the text visually selected, so clicking the same key a second time invokes the vmap for continued movement as described above. 2. The earlier versions did not work well when at the start or end of the line. 3. The earlier versions did not work well for the three different visual select modes (character/line/block). 4. Move by word. The original suggestion moves the text one character at a time. Powerful, but slow (and makes undo annoying). The suggestion below drags the selected text past one word at a time using or . This may not put you quite where you want, so after you get close, use the or to move past one character. 5. This may be overkill, but these mappings use "zv" to open any fold at the paste position. Remove "zv" if you are older than vim 6.0. Paste the rest of this post into your vimrc in order to try these mappings. " In order to use the arrow keys when visually selecting text: vnoremap h vnoremap l vnoremap k vnoremap j " Visually drag a block of text, one char/line at a time, using Ctrl-arrows. " Visually select a block of text, then press , , , " or repeatedly to drag the selection around, left/right by one " character, or up/down by one line at a time. " In order to behave nicely when the start or end of the text is reached, this " mapping first tests the move with something like lholh or jkojk. If the move " is not valid, then vim beeps, aborts the mapping, and everything is left as " it was. (The lholh tests both ends of the selection since there is no way to " explicitly test a specific end.) After the paste, there are a number of ways " to reselect the text, but the 1v is apparently the only way that works " properly for all visual select modes, and when the selection is at the end of " the line. For the up/down movements, this mapping uses "zv" to open any fold, " at the new location. If you are using a vim that doesn't support folds " (earlier than vim 6.0), remove the zv. " Beware, didn't work in vim80/2017. vnoremap lholhxp`[1v vnoremap hlohlxhP`[1v vnoremap jkojkxjzvP`[1v vnoremap kjokjxkzvP`[1v " Visually drag a block of text, one word/line at a time, using Alt-arrows. " The Alt-up/down mapping below is identical to the Ctrl-up/down mapping " above, but the Alt-left/right moves a word at a time (instead of one char). " Once you get the text close to where you want it using Alt-arrows, you can " switch to the Ctrl-arrows for final left/right adjustments. " These mappings work similar to the Ctrl-arrows above, but for the word " movements, testing for a valid move is tricky, since the cursor may be at " either end of the selection. So this mapping does an otherwise useless yank, " then re-selects in order to use `< and `>. " Remove "zv" if you are older than vim 6.0. " Beware, didn't work in vim80/2017. vnoremap y1vw`>xwzvP`[1v vnoremap y1vob` vnoremap jkojkxjzvP`[1v vnoremap kjokjxkzvP`[1v " You may prefer the mapping below, which moves the selection left by an " inner-word, stopping on both sides of white space. But there is no easy way " to do a similar A-Right, since this uses a mark, which does not move to the " new column when you delete text before the mark. "vnoremap y1voiwm`` " When nothing is selected, , , , or selects " the word under the cursor, and moves it one word in that direction. The " text remains selected, so pressing the same key again will invoke the " visual mapping above. " The "viw" portion selects an inner word; you may prefer to use "vaw", or " for the up/down arrows maybe you would rather select an entire line with " a big "V" instead of "viw". Otherwise, these mappings are similar to the " visual mappings above, although the valid-movement test is simpler here. " Remove "zv" if you are older than vim 6.0. " Beware, didn't work in vim80/2017. nnoremap viwm`w``xwzvP`[1v nnoremap viwm`bb``xbzvP`[1v nnoremap viwjkxjzvP`[1v nnoremap viwkjxkzvP`[1v The mappings of the original tip broke when words were dragged off the left & right edges of the line. Here are mappings that do not allow words to be dragged past the edges: vmap `gvxpgvoo ----